#pragma once

#include <Eigen/Dense>
#include <vector>
#include <stdint.h>
#include <chrono>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>


class VofaFrame
{
public:
    VofaFrame(std::string vofa_ip, int vofa_port);
    ~VofaFrame();

    void push(float value);
    void push(float v1, float v2);
    void push(float v1, float v2, float v3);
    void push(const Eigen::Vector3f& vec);
    void push(const Eigen::Vector3d& vec);

    void send();

    bool use_tcp = false;          // true=TCP, false=UDP
    bool tcp_connected = false;

private:
    int udp_sock = -1;
    int tcp_sock = -1;

    bool tcp_ready_to_send = false;

    sockaddr_in destAddr;
    std::vector<uint8_t> buffer_;

    std::chrono::steady_clock::time_point last_connect_time_point;
    std::chrono::steady_clock::time_point tcp_connected_time;
    int64_t reconnect_interval_ms = 2000;
    int64_t tcp_connect_delay_ms = 500;

    void connect_udp();
    void connect_tcp();
    void reset();
    std::vector<uint8_t> getFrame();
};
